class Solution {
public:
    int rob(vector<int>& nums) {
      int len = nums.size();
      if(len == 1) return nums[0];
      int dp[len+1];
      dp[0] = nums[0];
      dp[1] = nums[1];
      if(len == 2) return max(dp[0],dp[1]);
      for(int i = 2;i < len;i++){
        if(i % 2 == 0){
          dp[i] =max((dp[i-2] + nums[i]),dp[i-1]);
        }else{
          dp[i] = max(max(dp[i-2],dp[i-3])+nums[i],dp[i-1]);
        }
      }
      return dp[len-1];
    }
};
